package emulator.unittest.hardware.nmos6502.commands;

import static org.junit.Assert.assertEquals;

import org.junit.Test;

import emulator.EmulatorException;
import emulator.hardware.HwByte;
import emulator.hardware.clock.ClockImplementation;
import emulator.hardware.memory.MemoryBlock;
import emulator.hardware.nmos6502.Cpu6502;
import emulator.hardware.nmos6502.commands.JSR;
import emulator.unittest.hardware.nmos6502.MockOperand;

public class JSRTest {

	@Test
	public void testExecute() throws EmulatorException {
		Cpu6502 cpu = new Cpu6502();
		MemoryBlock memory = new MemoryBlock(65536);
		ClockImplementation clock = new ClockImplementation();
		cpu.attach(memory, clock);
		cpu.setPC(0x1A2B);
		cpu.setSP(new HwByte(0xFF));

		JSR jsr = new JSR();
		jsr.execute(cpu, new MockOperand(0xFFD2));
		assertEquals(0xFD, cpu.getSP().getNumber());
		assertEquals(0xFFD2, cpu.getPC());
		assertEquals(0x1A, memory.read(0x1FF));
		assertEquals(0x2A, memory.read(0x1FE));
	}

}
